package cn.iocoder.yudao.module.warehouseoperationlog.dal.mysql.warehouseoperationlog;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.warehouseoperationlog.dal.dataobject.warehouseoperationlog.WarehouseOperationLogDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.warehouseoperationlog.controller.admin.warehouseoperationlog.vo.*;

/**
 * 库房操作记录表（记录库房相关操作，支撑审计追溯） Mapper
 *
 * @author wwwhk
 */
//warehouseOperationLogMapper
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface WarehouseOperationLogMapper extends BaseMapperX<WarehouseOperationLogDO> {

    // 原分页方法保持不变
    default PageResult<WarehouseOperationLogDO> selectPage(WarehouseOperationLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseOperationLogDO>()
                .eqIfPresent(WarehouseOperationLogDO::getOperationType, reqVO.getOperationType())
                .orderByDesc(WarehouseOperationLogDO::getId));
    }

    // 修复联查分页方法：添加 Page 参数，返回 IPage
    IPage<WarehouseOperationLogWithWarehouseRespVO> selectPageWithWarehouse(
            @Param("page") Page<WarehouseOperationLogWithWarehouseRespVO> page,  // 分页参数
            @Param("query") WarehouseOperationLogPageReqVO queryVO  // 查询条件
    );

    // 保持原 insert 方法不变
    @Insert("INSERT INTO sys_warehouse_operation_log (warehouse_id, operation_type, operator_id, operation_time, remark, creator, updater) " +
            "VALUES (#{warehouseId}, #{operationType}, #{operatorId}, #{operationTime}, #{remark}, #{creator}, #{updater})")
    int insert(WarehouseOperationLogDO operationLog);
}